package com.taiji.dianthus.service.sys.impl;

import com.taiji.dianthus.common.BusinessMessage;
import com.taiji.dianthus.dao.sys.DictionaryRepository;
import com.taiji.dianthus.domain.sys.SysDictionary;
import com.taiji.dianthus.service.sys.DictionaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName DictionaryServiceImpl
 * @Description
 * @Author H.M
 * @Date 2020/6/4
 */
@Service("dict")
public class DictionaryServiceImpl implements DictionaryService {

    @Autowired
    private DictionaryRepository repository;


    /**
     * 保存方法
     *
     * @param dictionary
     * @return
     */
    @Override
    public BusinessMessage save(SysDictionary dictionary) {
        BusinessMessage message = new BusinessMessage();
        try {
            dictionary =repository.save(dictionary);
            message.setMsg("保存字典信息成功");
            message.setData(dictionary);
            message.setSuccess(true);
        }catch (Exception e) {
            e.printStackTrace();
            message.setMsg("保存字典信息失败，系统出错");
        }
        return message;
    }

    /**根据同类型查询字典集合
     * @param dictType
     * @return
     */
    @Override
    public List<SysDictionary> listByType(String dictType) {
        return repository.listByType(dictType);
    }

    /**
     * 根据条件获取字典属性名
     *
     * @param value
     * @param type
     * @return
     */
    @Override
    public String getDictName(String value, String type) {
        return repository.getDictName(value,type);
    }


}
